/**
 * 产品修改js
 */
var comValidform = null;
var returnStatus = false;
var pointsHistory = {
	curPage : 1,
	pageSize : 10,
	dataCache : null,

	// 设置分页
	setPageChange : function(delCurPage) {
		var url = 'mgr/pointsHistoryCtrl/list';
		var userRealName = $.trim($('#searchModForm input[name="userRealName"]').val());
		var params = {
			'curPage' : pointsHistory.curPage,
			'pageSize' : pointsHistory.pageSize,
			'userRealName' : userRealName
		};

		var cb = function(data) {
			if (data.resultCode == 200) {
				var totalCount = data.size;
				var pageTotal = (totalCount / pointsHistory.pageSize > 0) ? Math
						.ceil(totalCount / pointsHistory.pageSize) : 1;
				pageHelper.init(pageTotal, totalCount, pointsHistory.search,
						delCurPage); // 翻页事件
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	 
	},
	
	// 查询积分规则
	search : function(pageIdx) {
		var url = 'mgr/pointsHistoryCtrl/list';
		if (typeof (pageIdx) != "undefined") {
			pointsHistory.curPage = pageIdx;
		}
		var userRealName = $.trim($('#searchModForm input[name="userRealName"]').val());
		var params = {
			'curPage' : pointsHistory.curPage,
			'pageSize' : pointsHistory.pageSize,
			'userRealName' : userRealName
		};
		var cb = function(data) {
			$('#tableList tbody').empty();
			var tr = '';
			if (data.resultCode == 200) {
				if (data.result != null && data.result.length > 0) {
					for (var i = 0; i < data.result.length; i++) {
						var singleObj = data.result[i];
						var orderCreatedOn = getSmpFormatDateByLong(
								singleObj.cts, true);
						localStorage.setItem(singleObj.id + "_pointsHistory_Key",
								JSON.stringify(singleObj));

						tr += '<tr><td>'
								+ i
								+ '</td><td>'
								+ (singleObj.userName != null?singleObj.userName:"")
								+ '</td><td>'
								+ singleObj.score
								+ '</td><td>'
								+  singleObj.pointsId
								+ '</td><td>'
								+ singleObj.historyDesc
								+ '</td><td>'
								+ orderCreatedOn
								+ '</td></tr>';
					}
				} else {
					tr = '<tr><td colspan="7" style="text-align: center;color: red;">暂无数据</td></tr>';
				}
			} else {
				tr = '<tr><td colspan="7" style="text-align: center;color: red;">暂无数据</td></tr>';
			}
			$('#tableList tbody').html(tr);
			jsUtils.controlFunctionBtn();
			pointsHistory.bindEvent();
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},

	bindEvent : function() {
		// 查询
		$('#searchData').click(function() {
			pointsHistory.curPage = 1;
			pointsHistory.setPageChange(null);
			pointsHistory.search();
		});
	},

	init : function() {
		pointsHistory.setPageChange(null);
		pointsHistory.search();
	}
}
$(document).ready(function() {
	pointsHistory.init();
});
function submitForm() {
	comValidform.submitForm();
	return returnStatus;
}